package com.wei.charge.service;

import com.wei.charge.dao.ChargeMapper;
import com.wei.common.entity.Charge;
import com.wei.common.entity.Storage;
import com.wei.common.service.ChargeService;
import com.wei.common.service.StorageService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author weichuanyuan
 * @version 1.0
 * @date 2021/8/29 10:55
 */
@Service
@DubboService
public class ChargeServiceImpl implements ChargeService {
    @DubboReference
    private StorageService storageService;

    @Autowired
    private ChargeMapper chargeMapper;
    @Override
    public boolean Charging(Charge charge) {
        System.out.println("扣费");
        chargeMapper.insert(charge);

        Storage storage = new Storage();
        storage.setProductId(1);
        storage.setProductNumber(new BigDecimal(2));
        //storageService.reduceStorage(storage);
        storageService.reduceStorageException(storage);
        return true;
    }
}
